package com.boot.dog.common.enums;

import java.util.HashMap;
import java.util.Map;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: MaxLv
 * @Date: 2019/12/2
 */
@Getter
@AllArgsConstructor
public enum ButtonType implements EnumConst {

    VIEW("view", "查看", "md-eye"),

    ADD("add", "添加", "md-add"),

    EDIT("edit", "编辑", "md-create"),

    EDIT_PERM("editPerm", "分配菜单权限", "md-swap"),

    EDIT_DATA_PERM("editDataPerm", "分配区域权限", "md-infinite"),

    ALLOT("allot", "分配", "md-archive"),

    DELETE("delete", "删除", "md-trash"),

    ENABLE_DISABLE("enableDisable", "启用/禁用", "md-unlock"),

    SEARCH("search", "检索", "md-search"),

    UPLOAD("upload", "上传", ""),

    OUTPUT("output", "导出", "md-arrow-round-up"),

    INPUT("input", "导入", ""),

    OTHER("other", "其他", "");

    private final String code;
    private final String text;
    private final String icon;

    @Override
    public String code() {
        return this.code;
    }

    @Override
    public String text() {
        return this.text;
    }

    public String icon() {
        return this.icon;
    }

    private static final Map<String, String> codeMap = new HashMap<>();
    private static final Map<String, String> codeIconMap = new HashMap<>();

    static {
        for (ButtonType item : values()) {
            codeMap.put(item.code(), item.text());
            codeIconMap.put(item.code(), item.icon());
        }
    }

    @Override
    public boolean isValid(String code) {
        if (StrUtil.isEmpty(code)) {
            return false;
        }
        return codeMap.containsKey(code);
    }

    /**
     * 获取名称
     *
     * @param code
     * @return
     */
    public static String getText(String code) {
        if (codeMap.containsKey(code)) {
            return codeMap.get(code);
        }
        return StrUtil.EMPTY;
    }

    /**
     * 获取ICON
     *
     * @param code
     * @return
     */
    public static String getIcon(String code) {
        if (codeIconMap.containsKey(code)) {
            return codeIconMap.get(code);
        }
        return StrUtil.EMPTY;
    }
}
